package org.example.redis;

import lombok.extern.slf4j.Slf4j;
import org.example.redis.impl.CountLimiter;

@Slf4j
public class LimiterTest {

    public static void main(String[] args) throws InterruptedException {
        // 1秒只能10个请求，超过就算令牌失败
        Limiter limiter = new CountLimiter();
        for (int i = 0; i < 100; i++) {
            if (limiter.tryAcquire(1)) {
                log.info("获取令牌成功");
                Thread.sleep(100);
            } else {
                log.info("获取令牌失败");
            }
        }
    }
}
